
function switchEditor (id, ev) {
  $('.acleItem').hide()
  let $id = '#' + id + ''
  $($id).show()
  let activeItem = document.getElementsByClassName('aclm-active')
  
  for(i=0;i<activeItem.length;i++) {
    activeItem[i].className = activeItem[i].className.replace(' aclm-active', '')
  }
  ev.target.parentNode.id ? ev.target.parentNode.className += ' aclm-active' : ev.target.parentNode.parentNode.className += ' aclm-active'
}

function comDel (ev) {
  layui.use('layer', function(){
    layer.confirm('删除该模板后，所有编辑的内容将会初始化。', {
      title: '确认删除？',
      btn: ['确认', '取消'] //可以无限个按钮
    }, function(index, layero){
      let delid = '#' + ev.target.parentNode.parentNode.getAttribute('id')
      $(delid).remove()
      layer.close(index);
    }, function(index){
      //按钮【按钮二】的回调
    });
  });
}

function openEdit (com) {
  if ($('.a-c-r-comEdit').css('display') == 'block') {
    $('.a-c-r-comEdit').slideUp()
    return
  }

  // if ($('.acrc-b-title').css('display') || $('.acrc-b-info').css('display') == 'block') {
  //   $('.a-c-r-comEdit').slideUp()
  // }

  $('.a-c-r-comEdit').slideDown()

  if (com === "info") {
    $('.acrc-item').hide()
    $('.acrc-b-info').show()
    let cont = $('#webPage').find('.b-i-content').html()
    // let $cont = cont.cloneNode(true)
    $('.acrc-b-i-content').html(cont)
    $('.acrc-b-i-content').find('.b-i-c-item').css('display', 'block')
                                              .css('width', '100%')
    $('.acrc-b-i-content').find('.bici-key').css('border', '0.01rem solid #ccc')
    $('.acrc-b-i-content').find('.bici-value').css('display', 'inline')
                                              .css('overflow', 'hidden')
    return
  }

  if (com === "title") {
    $('.acrc-item').hide()
    $('.acrc-b-title').show()
    return
  }
  if (com === "custom") {
    $('.acrc-item').hide()
    $('.acrc-b-custom').show()
    return
  }
}
function cancelEdit () {
  $('.a-c-r-comEdit').slideUp()
}

function confirmEdit () {
  let _cont = $('.a-c-r-comEdit').find('.acrc-b-i-content').html()
  console.log(_cont)
  $('#webPage').find('.b-i-content').html(_cont)
  $('#webPage').find('.b-i-c-item').css('display', 'inline-block')
                                   .css('width', '48%')
  $('#webPage').find('.bici-key').css('border', 'none')
  $('#webPage').find('.bici-value').css('display', 'inline-block')
                                   .css('overflow', 'none')
  $('.a-c-r-comEdit').slideUp()
}

function changeValue(ev) {
  console.log(ev.target.value)
  ev.target.setAttribute('value', ev.target.value)
}

function info_valCalc(num) {
  let info_fontSize = Number(document.getElementById('acrc-bi-z-value').innerHTML) + num
  document.getElementById('acrc-bi-z-value').innerHTML = Number(document.getElementById('acrc-bi-z-value').innerHTML) + num
  $('#webPage').find('.builder-info').css('font-size', info_fontSize)

}

function title_valCalc(num) {
  let title_fontSize = Number(document.getElementById('acrc-bt-z-value').innerHTML) + num
  document.getElementById('acrc-bt-z-value').innerHTML = Number(document.getElementById('acrc-bt-z-value').innerHTML) + num
  $('#webPage').find('.builder-title').css('font-size', title_fontSize)
}

function title_textchg (ev) {
  $('#webPage').find('.builder-title').html(ev.target.value)
}

function custom_textchg (ev) {
  $('#webPage').find('.builder-custom').html(ev.target.value)
}

function title_align(n) { 
  for (i=0;i<$('.acrc-bt-z-checkbox').length;i++) {
    if (i == n) {
      console.log($('.acrc-bt-z-checkbox')[i])
      $('.acrc-bt-z-checkbox')[i].checked = true
    } else {
      $('.acrc-bt-z-checkbox')[i].checked = false
    }
    
  }

  if (n === 0) {
    $('#webPage').find('.builder-title').css('text-align', 'left')
    return
  }
  if (n === 1) {
    $('#webPage').find('.builder-title').css('text-align', 'center')
    return
  }
  if (n === 2) {
    $('#webPage').find('.builder-title').css('text-align', 'right')
    return
  }
}

function custom_align(n) { 
  for (i=0;i<$('.acrc-bc-z-checkbox').length;i++) {
    if (i == n) {
      console.log($('.acrc-bc-z-checkbox')[i])
      $('.acrc-bc-z-checkbox')[i].checked = true
    } else {
      $('.acrc-bc-z-checkbox')[i].checked = false
    }
    
  }

  if (n === 0) {
    $('#webPage').find('.builder-custom').css('text-align', 'left')
    return
  }
  if (n === 1) {
    $('#webPage').find('.builder-custom').css('text-align', 'center')
    return
  }
  if (n === 2) {
    $('#webPage').find('.builder-custom').css('text-align', 'right')
    return
  }
}